package com.ruihu.admin.module.business.task.domain.entity;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruihu.admin.common.domain.BaseEntity;
import java.util.Date;
import java.util.Objects;

import com.ruihu.admin.module.business.task.domain.dto.TaskAddDTO;
import com.ruihu.admin.module.business.task.domain.dto.TaskUpdateDTO;
import lombok.Data;

/**
 * [ 任务主表 ]
 *
 * @author Tony
 * @version 1.0
 * @company 瑞虎（南京）信息技术有限公司
 * @copyright (c)  瑞虎（南京）信息技术有限公司Inc. All rights reserved.
 * @date 2022-08-26 20:42:35
 * @since JDK1.8
 */
@Data
@TableName("t_task")
public class TaskEntity extends BaseEntity {


    /**
     * 任务编号
     */
    private String taskCode;

    /**
     * 任务名称
     */
    private String taskName;

    /**
     * 任务描述
     */
    private String taskDesc;

    /**
     * 计划总数
     */
    private Integer planNum;

    /**
     * 计划开始时间
     */
    private Date planStartTime;

    /**
     * 计划结束时间
     */
    private Date planEndTime;

    /**
     * 任务优先级ID
     */
    private Long priorityId;

    /**
     * 完成时间
     */
    private Date completionTime;

    /**
     * 状态
     */
    private String status;

    /**
     * 删除标识
     */
    private String isDelete;

    /**
     * 乐观锁
     */
    private Integer revision;

    /**
     * 创建人
     */
    private Long createBy;


    /**
     * 更新人
     */
    private Long updateBy;

    public static TaskEntity convertToTaskEntity(TaskAddDTO taskAddDTO) {
        if (taskAddDTO == null) {
            return null;
        }
        TaskEntity taskEntity = new TaskEntity();
        taskEntity.setTaskName(taskAddDTO.getTaskName());
        taskEntity.setTaskDesc(taskAddDTO.getTaskDesc());
        taskEntity.setPlanNum(taskAddDTO.getPlanNum());
        taskEntity.setPlanStartTime(taskAddDTO.getPlanStartTime());
        taskEntity.setPlanEndTime(taskAddDTO.getPlanEndTime());
        taskEntity.setPriorityId(taskAddDTO.getPriorityId());

        return taskEntity;
    }

    public static TaskEntity convertToTaskEntity(TaskUpdateDTO taskUpdateDTO) {
        if (taskUpdateDTO == null) {
            return null;
        }
        TaskEntity taskEntity = new TaskEntity();
        taskEntity.setId(taskUpdateDTO.getId());
        taskEntity.setTaskName(taskUpdateDTO.getTaskName());
        taskEntity.setTaskDesc(taskUpdateDTO.getTaskDesc());
        taskEntity.setPlanNum(taskUpdateDTO.getPlanNum());
        taskEntity.setPlanStartTime(taskUpdateDTO.getPlanStartTime());
        taskEntity.setPlanEndTime(taskUpdateDTO.getPlanEndTime());
        taskEntity.setPriorityId(taskUpdateDTO.getPriorityId());
        return taskEntity;
    }

    public static TaskEntity copyIgnoreNullAndEmpty(TaskEntity sourceEntity, TaskEntity destEntity) {
        if (Objects.isNull(sourceEntity))
            return destEntity;
        if (StrUtil.isNotEmpty(sourceEntity.getTaskCode()))
            destEntity.setTaskCode(sourceEntity.getTaskCode());
        if (StrUtil.isNotEmpty(sourceEntity.getTaskName()))
            destEntity.setTaskName(sourceEntity.getTaskName());
        if (StrUtil.isNotEmpty(sourceEntity.getTaskDesc()))
            destEntity.setTaskDesc(sourceEntity.getTaskDesc());
        if (Objects.nonNull(sourceEntity.getPlanNum()))
            destEntity.setPlanNum(sourceEntity.getPlanNum());
        if (Objects.nonNull(sourceEntity.getPlanStartTime()))
            destEntity.setPlanStartTime(sourceEntity.getPlanStartTime());
        if (Objects.nonNull(sourceEntity.getPlanEndTime()))
            destEntity.setPlanEndTime(sourceEntity.getPlanEndTime());
        if (Objects.nonNull(sourceEntity.getPriorityId()))
            destEntity.setPriorityId(sourceEntity.getPriorityId());
        if (Objects.nonNull(sourceEntity.getCompletionTime()))
            destEntity.setCompletionTime(sourceEntity.getCompletionTime());
        if (StrUtil.isNotEmpty(sourceEntity.getStatus()))
            destEntity.setStatus(sourceEntity.getStatus());
        if (Objects.nonNull(sourceEntity.getRevision()))
            destEntity.setRevision(sourceEntity.getRevision());
        if (Objects.nonNull(sourceEntity.getCreateBy()))
            destEntity.setCreateBy(sourceEntity.getCreateBy());
        if (Objects.nonNull(sourceEntity.getUpdateBy()))
            destEntity.setUpdateBy(sourceEntity.getUpdateBy());
        if (Objects.nonNull(sourceEntity.getId()))
            destEntity.setId(sourceEntity.getId());
        if (Objects.nonNull(sourceEntity.getUpdateTime()))
            destEntity.setUpdateTime(sourceEntity.getUpdateTime());
        if (Objects.nonNull(sourceEntity.getCreateTime()))
            destEntity.setCreateTime(sourceEntity.getCreateTime());
        return destEntity;
    }
}
